<?php 
	include 'db.php';
	
	//select current user shopping cart and get total
function printCart(){
    $id_session = session_id();
    $totalVal = 0;
	$totalCost = 0;
 
    $sql = "SELECT *
            FROM cart
            INNER JOIN items
            ON cart.itemId = items.itemId
            WHERE cart.sessionId = '" . $id_session . "'";
 
    //open the table and print a header row
		echo '<table class="table table-bordered">';  
		echo '<thead><tr>';
		echo ' <th>PH Code</th>';
		echo ' <th>Item Description</th>';
		echo '<th>Quantity</th>';
		echo '<th>Unit Price</th>';
		echo '<th>Total Value</th>';
		echo '</tr></thead>';
		echo '<tbody>';

    if ($result=mysql_query($sql)) {
      while ($row=mysql_fetch_array($result)) {
		  
		echo '<tr>';
		echo '<td>'.$row['phCode'].'</td>';
		echo '<td>'.$row['itemName'].' '.$row['itemDesc'].'</td>';
		echo '<td>'.$row['qty'].'</td>';
		echo '<td>'.$row['itemPrice'].'</td>';
		$totalVal = $row['qty'] * $row['itemPrice'];
		echo '<td>' .$totalVal. '</td>';
		echo '</tr>';
		$totalCost += $row["qty"] * $row["itemPrice"]; 
		/* echo"<div class=\"itemRow\"><div class=\"itemWrap\">";
		echo "<strong>".$row['qty']."</strong> piece(s) of ";
        echo "".$row['itemName']." ";
        echo ' - ';
        echo "".$row['itemDesc']." ";
        echo "<strong>".$row['itemPrice']."</strong></div><div class=\"itemCtrl\"> <a title=\"remove this item\" class=\"decrease-item\" href=\"remove.php?id=".$row['cartId']."\">( remove ) </a>";
		echo ' <a class="add-item" title="add more of this item" href="cart.php?action=add_item&id='.$row['itemId'].'">(+)</a>'; // increment item button
		echo ' <a class="minus-item" title="subtract item quantity" href="minus.php?id='.$row['itemId'].'&cartId='.$row['cartId'].'&qty='.$row['qty'].'">(-)</a><div class="clear"></div></div><div class="clear"></div></div>'; //decrement item button
        //multiplay quantity and itemprice to get total of 1 product all together
        $totalCost += $row["qty"] * $row["itemPrice"]; */
      } 
	  	echo '<tr>';
		echo '<td colspan="3">&nbsp;</td>';
		echo '<td><strong>TOTAL AED</strong></td>';
		echo '<td><strong>'.$totalCost.'</strong></td>';
		echo '</tr>';  
		echo '</tbody>';
		echo '</table>'; 
	 } else {
      echo mysql_error();
    }
}
?>